Imports System.xml
Imports System.Windows.Forms


Public Class FormAddNewTemplate

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try

            SaveNewItem()

            Me.DialogResult = Windows.Forms.DialogResult.OK
        Catch ex As Exception
            Dim mylog As New LogFile
            mylog.WriteToLog(ex.Message.ToString & " " & ex.InnerException.ToString)
        End Try


    End Sub


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Catch ex As Exception
            Dim mylog As New LogFile
            mylog.WriteToLog(ex.Message.ToString & " " & ex.InnerException.ToString)
        End Try

    End Sub

    Private Sub SaveNewItem()

        Try
            Dim xmlDocument As XmlDocument = New XmlDocument
            Dim strXML As String = String.Empty
            xmlDocument.Load(My.Computer.FileSystem.CurrentDirectory & "\Plugins\TagTemplates.xml")

            Dim docFrag As XmlDocumentFragment = xmlDocument.CreateDocumentFragment()
            strXML = "<site name=""" & txtSite.Text.Trim.ToString & """>" & _
            "<tagFormat><![CDATA[" & txtTagFormat.Text.Trim.ToString & "]]></tagFormat>" & _
            "<inUse>"
            If chkInUse.Checked = True Then
                strXML = strXML & "true"
            Else
                strXML = strXML & "false"
            End If
            strXML = strXML & "</inUse></site>"
            docFrag.InnerXml = strXML

            xmlDocument.DocumentElement.AppendChild(docFrag)
            xmlDocument.Save(My.Computer.FileSystem.CurrentDirectory & "\Plugins\TagTemplates.xml")

        Catch ex As Exception

            Dim mylog As New LogFile
            mylog.WriteToLog(ex.Message.ToString & " " & ex.InnerException.ToString)

        End Try

    End Sub

    Private Sub FormAddNewTemplate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            txtSite.Text = "Name of Site"
            txtTagFormat.Text = "<a href=""http://www.url.com/search?q={tag}"">{tag}</a>"
            chkInUse.Checked = True
        Catch ex As Exception

            Dim mylog As New LogFile
            mylog.WriteToLog(ex.Message.ToString & " " & ex.InnerException.ToString)

        End Try
    End Sub
End Class



